$package('itsm.system');

itsm.system.splitMain=function(){
	this.opt='';
	return {
		//列表
		splitMainGrid:function(){
			var params = $.extend({},jqGridParams, {	
				url:'trans!findTransactionRecordPager.action?trDTO.transactionType=split',
				caption:'拆分日志',
				colNames:['ID','拆分次数','拆分时间','拆分前股数','拆分前股价','拆分前待处理股数','拆分倍数','拆分后股数','拆分后股价','拆分后待处理股数','玩家'],
			 	colModel:[
			 	          {name:'recordId',align:'center'},
			 	          {name:'splitNumber',align:'center'},
			 	          {name:'optDate',align:'center'},
			 	          {name:'splitBeforeShare',align:'center'},
			 	          {name:'splitBeforeSharePrice',align:'center'},
			 	          {name:'splitBeforePendingShare',align:'center'},
			 	          {name:'splitMultiples',align:'center'},
			 	          {name:'splitAfterShare',align:'center'},
			 	          {name:'splitAfterSharePrice',align:'center'},
			 	          {name:'splitAfterPendingShare',align:'center'},
			 	         {name:'loginName',align:'center'},
			 	],
				jsonReader: $.extend(jqGridJsonReader, {id: "recordId"}),
				sortname:'recordId',
				pager:'#splitMainPager'
				});
				$("#splitMainGrid").jqGrid(params);
				$("#splitMainGrid").navGrid('#splitMainPager',navGridParams);
				//列表操作项
				$("#t_splitMainGrid").css(jqGridTopStyles);
				$("#t_splitMainGrid").html($('#splitMainGridToolbar').html());
				
				//自适应宽度
				setGridWidth("#transMainGrid","regCenter",10);
		},
		//打开添加窗口
		openAddWin:function(){
			opt='saveRule';
			resetForm('#splitMain_add_form');
			$('#splitMain_add_win').window('open');
		},
		
		//打开编辑窗口
		openEditWin:function(){
			opt='editRule';
			checkBeforeEditGrid('#splitMainGrid',function(rowData){
				$.post('trans!findRuleByRuleCode.action','ruleDTO.ruleCode='+rowData.ruleCode,function(data){
					$('#splitMain_ruleId').val(data.ruleId);
					$('#splitMain_ruleName').val(data.ruleName);
					$('#transMain_ruleCode').val(data.ruleCode);
					$('#splitMain_ruleValue').val(data.ruleValue);
				});
				$('#splitMain_add_win').window('open');
			});	
		},
		
		//保存
		saveSplit:function(){
			if($('#splitMain_add_win').form('validate')){
				var _param = $('#splitMain_add_win form').serialize();
				$.post('trans!'+opt+'.action',_param,function(data){
					msgShow('保存成功!','show');
					$('#splitMain_add_win').window('close');
					$('#splitMainGrid').trigger('reloadGrid');
				})
				
			}
		},
		//删除
		deleteSplit:function(){
			checkBeforeDeleteGrid('#splitMainGrid',function(rowIds){
				var pp = $.param({'ids':rowIds},true);
				$.post("trans!deleteTrans.action", pp, function(){
					$('#splitMainGrid').trigger('reloadGrid');
					msgShow('删除成功!','show');
				}, "json");
			});
		},
		//打开搜索窗口
		openSearchWin:function(){
			$('#splitMain_search_win').window('open');
		},
		//搜索
		searchSplit:function(){
			var sdata=$('#splitMain_search_win form').getForm();
			var postData = $("#splitMainGrid").jqGrid("getGridParam", "postData");
			$.extend(postData,sdata);
			var _url = 'trans!findTransactionRecordPager.action';		
			$('#splitMainGrid').jqGrid('setGridParam',{url:_url}).trigger('reloadGrid',[{"page":"1"}]);
		},
		
		//拆分
		startSplit:function(){
			$.messager.confirm('操作提示','<br/>是否真的要拆分?',function(r){
				if(r){
					$('#splitResult').text('正在拆分中，请稍等.......');
					$.post("sell!splitShare.action",function(){
						$('#splitMainGrid').trigger('reloadGrid');
						$('#splitResult').text('拆分操作成功');
						msgShow('拆分成功!','show');
					}, "json");
				}
			});
			
		},
		init:function(){
			itsm.system.splitMain.splitMainGrid();
		}
	}
	
}();

$(function(){
	itsm.system.splitMain.init();
});